package com.xm.xmapp.base;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.http.NetWorkData;
import com.xm.xmapp.tool.AndroidTool;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import butterknife.ButterKnife;

/**
 * Created by LDW on 2017/7/14.
 */
public abstract class BaseActivity extends AppCompatActivity {
    private Bundle savedInstanceState;
    public NetWorkData mNetWorkData;
    public Intent intent;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.savedInstanceState = savedInstanceState;
        requestWindowFeature(Window.FEATURE_NO_TITLE);
//        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//            getWindow().setBackgroundDrawableResource(R.mipmap.window_bg);
//            getWindow().getDecorView().setSystemUiVisibility(
//                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN|View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//            getWindow().setStatusBarColor(Color.TRANSPARENT);
//        }

        Class<? extends Window> clazz = getWindow().getClass();
        try {
            int darkModeFlag = 0;
            Class<?> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
            Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
            darkModeFlag = field.getInt(layoutParams);
            Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
            extraFlagField.invoke(getWindow(), true ? darkModeFlag : 0, darkModeFlag);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        ButterKnife.bind(this);
        initView(savedInstanceState);
    }

    public void getNetWorkData(ReqBaseBean reqBaseBean , int code){
        if(mNetWorkData!=null && reqBaseBean!=null) {
            MyAppcation.getMyAppcation().getPostData(this, reqBaseBean, mNetWorkData, code);
        } else {
            AndroidTool.showMessage("请先初始化参数");
        }
    }
    public abstract void initView(Bundle savedInstanceState);

}
